package org.csu.question.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.csu.question.entity.po.KnowledgePoint;

import java.util.List;

@Mapper
public interface KnowledgePointMapper extends BaseMapper<KnowledgePoint> {

    /**
     * 根据标签查询知识点
     */
    @Select("SELECT * FROM knowledge_points WHERE tag = #{tag}")
    List<KnowledgePoint> selectByTag(String tag);

    /**
     * 查询所有根知识点（无父节点）
     */
    @Select("SELECT * FROM knowledge_points WHERE parent_id IS NULL")
    List<KnowledgePoint> selectRootKnowledgePoints();

    /**
     * 根据父ID查询子知识点
     */
    @Select("SELECT * FROM knowledge_points WHERE parent_id = #{parentId}")
    List<KnowledgePoint> selectByParentId(Long parentId);
}
